package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<NursingLevel[]> listAll(){
         NursingLevel[] nursingLevels=nursingLevelService.listAll();
        return success(nursingLevels);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.addNursingLevel(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevel>> list(@ApiParam(value = "护理等级名称", required = false) String name,
                                                           @ApiParam(value = "当前页码", defaultValue = "1")Integer pageNum,
                                                           @ApiParam(value = "当前页码", defaultValue = "10")Integer pageSize,
                                                           @ApiParam(value = "状态", required = false)Integer status){
        PageResponse<NursingLevel> pageResponse=nursingLevelService.list(name,pageNum,pageSize,status);
        return success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingLevel> findById(@PathVariable @ApiParam(value = "ID", required = true) Long id){
        NursingLevelVo nursingLevelVo=nursingLevelService.findById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable @ApiParam(value = "ID", required = true) Long id){
        nursingLevelService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用或禁用")
    public ResponseResult enableOrDisable(@PathVariable @ApiParam(value = "ID", required = true) Long id,
                                          @PathVariable @ApiParam(value = "状态", required = true) Integer status){
        nursingLevelService.updateStatus(id,status);
        return success();
    }

}
